//    Copyright (C) Kherty.  All rights reserved.
using System.Windows.Media;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing
{
    public abstract class ColorTransform : IOfficeXmlSerializable
    {
        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            ReadXmlCore(context);
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            WriteXmlCore(context);
        }

        #endregion

        internal static ColorTransform ReadTransform(ReadContext context)
        {
            switch (context.ReaderLocalName)
            {
                case "tint":
                    return context.ReadElement<TintTransform>();
                case "satMod":
                    return context.ReadElement<SaturationModulationTransform>();
                case "shade":
                    return context.ReadElement<ShadeTransform>();
                case "alpha":
                    return context.ReadElement<AlphaTransform>();
                case "hueMod":
                    return context.ReadElement<HueModulationTransform>();
                case "gamma":
                    return context.ReadElement<GammaTransform>();
                case "invGamma":
                    return context.ReadElement<InverseGammaTransform>();
                case "lumMod":
                    return context.ReadElement<LuminanceModulationTransform>();
                case "lumOff":
                    return context.ReadElement<LuminanceOffsetTransform>();
                case "comp":
                    return context.ReadElement<ComplementTransform>();
                case "inv":
                    return context.ReadElement<InverseTransform>();
                case "gray":
                    return context.ReadElement<GrayscaleTransform>();
                case "alphaOff":
                    return context.ReadElement<AlphaOffsetTransform>();
                case "alphaMod":
                    return context.ReadElement<AlphaModulationTransform>();
                case "hue":
                    return context.ReadElement<HueTransform>();
                case "hueOff":
                    return context.ReadElement<HueOffsetTransform>();
                case "sat":
                    return context.ReadElement<SaturationTransform>();
                case "satOff":
                    return context.ReadElement<SaturationOffsetTransform>();
                case "lum":
                    return context.ReadElement<LuminanceTransform>();
                case "red":
                    return context.ReadElement<RedTransform>();
                case "redOff":
                    return context.ReadElement<RedOffsetTransform>();
                case "redMod":
                    return context.ReadElement<RedModulationTransform>();
                case "green":
                    return context.ReadElement<GreenTransform>();
                case "greenOff":
                    return context.ReadElement<GreenOffsetTransform>();
                case "greenMod":
                    return context.ReadElement<GreenModulationTransform>();
                case "blue":
                    return context.ReadElement<BlueTransform>();
                case "blueOff":
                    return context.ReadElement<BlueOffsetTransform>();
                case "blueMod":
                    return context.ReadElement<BlueModulationTransform>();
                default:
                    return null;
            }
        }

        public abstract Color Apply(Color c);

        internal abstract void ReadXmlCore(ReadContext context);

        internal abstract void WriteXmlCore(WriteContext context);
    }
}